<template>
	<view class="content">
		<view class="hei20"></view>
		<view class="wid90 mar borRad20 coFFF" style="background-color: #035DFF;">
			<view class="wid87 mar">
				<view style="height: 50rpx;"></view>
				<view class="foSi40 fowe600">今日收银</view>
				<view class="foSi40" style="vertical-align: bottom;margin-top: 50rpx;">
					<span>¥</span>
					<span class="fowe600 foSi60">{{today}}</span>
				</view>
				<view style="height: 66rpx;"></view>
			</view>
		</view>
		<view class="wid90 mar bacFFF borRad20 " style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);margin-top: 50rpx;">
			<view class="wid87 mar">
				<view class="hei20"></view>
				<view class="fowe600 foSi40 mar-top20 mar-bott30">收银明细</view>
				<scroll-view style="max-height: 818rpx;" class="wid100" scroll-y="true" @scrolltolower="lower">
					<block v-for="(item,index) in list" :key="index">
						<view class="dis disAl mar-bott30">
							<view style="width: 15%;">
								<image src="../../static/yue1.png" style="width: 48rpx;height: 58rpx;"></image>
							</view>
							<view class="dis disAl disJuB wid85">
								<view>
									<view class="foSi30">{{userInfo.name}}收银</view>
									<view class="foSi25" style="color: #010101;">{{dateFormat(item.paytime)}}</view>
								</view>
								<view class="foSi35" style="color: #035DFF;">+{{item.pay_amount}}</view>
							</view>
						</view>
					</block>
					<view class="dis disAl disJuC foSi25 hei80" style="color: #010101;">{{jiazai}}</view>
				</scroll-view>
				<view style="height: 30rpx;"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				today: 0,
				list: [],
				jiazai: '加载更多',
				last_page: 0,
				page: 1,
				userInfo: ''
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync('yuan_userinfo')
			this.getList()
		},
		onShow() {},
		methods: {
			dateFormat(time) {
				let date = new Date(time*1000);
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				return year + "-" + month + "-" + day+ " " + hours + ":" + minutes + ":" + seconds;
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_clerk_cashier',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						'gas_station_id': uni.getStorageSync('yuan_userinfo').gas_station_id,
						'page': that.page,
						'limit': 10,
						'clerk_id': that.userInfo.id
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.last_page = result.data.order.last_page
							that.list = that.list.concat(result.data.order.data)
							that.today = result.data.today
							if(result.data.order.data.length < 10){
								that.jiazai = '暂无更多'
							}else{
								that.jiazai = '加载更多'
							}
						}
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.jiazai = '加载中...'
					this.page++
					this.getList()
				}else{
					this.jiazai = '暂无更多'
				}
			},
		}
	}
</script>

<style>
	.content {
		background: #fff;
		height: 100vh;
	}
</style>
